<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="Linux内核模块功能定制编译内核：程序包的编译安装：.&#x2F;configure ,make ,make install配置参数，make是项目构建工具，调用各种编译工具完成构建，二进制文件，库文件，配置文件，帮助文件，make install 完成复制 编译前提：开发环境开发工具（gcc）、开发库（API）库和头文件&#x2F;usr&#x2F;include&#x2F; 开源：源代码–可执行格式发行版：以通用为目标；主包:支包">
<meta property="og:type" content="article">
<meta property="og:title" content="22.Linux内核模块功能定制">
<meta property="og:url" content="http://yoursite.com/2020/06/22/22-Linux%E5%86%85%E6%A0%B8%E6%A8%A1%E5%9D%97%E5%8A%9F%E8%83%BD%E5%AE%9A%E5%88%B6/index.html">
<meta property="og:site_name" content="Lcxiao&#39;s blog">
<meta property="og:description" content="Linux内核模块功能定制编译内核：程序包的编译安装：.&#x2F;configure ,make ,make install配置参数，make是项目构建工具，调用各种编译工具完成构建，二进制文件，库文件，配置文件，帮助文件，make install 完成复制 编译前提：开发环境开发工具（gcc）、开发库（API）库和头文件&#x2F;usr&#x2F;include&#x2F; 开源：源代码–可执行格式发行版：以通用为目标；主包:支包">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-06-22T06:57:32.000Z">
<meta property="article:modified_time" content="2020-06-22T14:57:55.731Z">
<meta property="article:author" content="lcxiao">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yoursite.com/2020/06/22/22-Linux%E5%86%85%E6%A0%B8%E6%A8%A1%E5%9D%97%E5%8A%9F%E8%83%BD%E5%AE%9A%E5%88%B6/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>22.Linux内核模块功能定制 | Lcxiao's blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="Lcxiao's blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Lcxiao's blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-lifestyle">

    <a href="/lifestyle/" rel="section"><i class="fa fa-fw fa-lifestyle"></i>LifeStyle</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/06/22/22-Linux%E5%86%85%E6%A0%B8%E6%A8%A1%E5%9D%97%E5%8A%9F%E8%83%BD%E5%AE%9A%E5%88%B6/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lcxiao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lcxiao's blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          22.Linux内核模块功能定制
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-06-22 14:57:32 / 修改时间：22:57:55" itemprop="dateCreated datePublished" datetime="2020-06-22T14:57:32+08:00">2020-06-22</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="Linux内核模块功能定制"><a href="#Linux内核模块功能定制" class="headerlink" title="Linux内核模块功能定制"></a>Linux内核模块功能定制</h1><h2 id="编译内核："><a href="#编译内核：" class="headerlink" title="编译内核："></a>编译内核：</h2><p>程序包的编译安装：<br>./configure ,make ,make install<br>配置参数，make是项目构建工具，调用各种编译工具完成构建，<br>二进制文件，库文件，配置文件，帮助文件，make install 完成复制</p>
<p>编译前提：开发环境<br>开发工具（gcc）、开发库（API）库和头文件/usr/include/</p>
<p>开源：源代码–可执行格式<br>发行版：以通用为目标；主包:支包 选择性安装功能<br>实在需要发行版没有编译进的功能的话，只有自己编译了</p>
<h2 id="准备工作："><a href="#准备工作：" class="headerlink" title="准备工作："></a>准备工作：</h2><ul>
<li>开发环境；</li>
<li>目标主机硬件设备的相关信息；</li>
<li>获取目标主机系统功能的相关信息，要启用的文件系统；</li>
<li>获取内核代码：<a href="http://www.kernel.org" target="_blank" rel="noopener">www.kernel.org</a></li>
</ul>
<p>CentOS6,7：<br>    Development Tools<br>    Server Platform Development</p>
<p>确保安装的包组里面有ncurses包</p>
<p>获取目标主机上硬件的信息<br>CPU:<br>    cat /proc/cpuinfo<br>    lscpu<br>    x86info -a(包x86info)<br>PCI:<br>    lspci<br>    -v<br>    -vv</p>
<p>USB:<br>    lsusb<br>    -v<br>    -vv</p>
<p>lsblk</p>
<p>全部硬件设备信息：<br>    hal-device<br>    lshw</p>
<h2 id="编译过程"><a href="#编译过程" class="headerlink" title="编译过程"></a>编译过程</h2><pre><code>解压内核文件到/usr/src
tar xvf kernel.tar.gz -C /usr/src
ln -sv linux-x.x.x linux
cd linux
make menuconfig         #编译内核选项
make -j CPU核心数
make modules_install    #安装内核模块
make install            #安装内核</code></pre><p>make –help</p>
<h2 id="screen"><a href="#screen" class="headerlink" title="screen:"></a>screen:</h2><pre><code>打开新的screen窗口：screen
命名新窗口：screen -S TITLE_NAME
拆除screen： ctrl+a，d
列出screen：screen -ls
连接至screen：screen -r SCREEN_ID
关闭screen：在screen内部exit</code></pre><p>screen不会因为ssh的连接断开而中断任务</p>
<h3 id="模板文件"><a href="#模板文件" class="headerlink" title="模板文件"></a>模板文件</h3><p>复制/boot目录下的配置文件作为模板，之后修改这个文件</p>
<p>内核配置模板文件：<br>有些发行版在/boot目录下有配置文件模板<br>有的在/proc/config.gz</p>
<h2 id="（1）配置内核选项"><a href="#（1）配置内核选项" class="headerlink" title="（1）配置内核选项"></a>（1）配置内核选项</h2><h3 id="详细说明："><a href="#详细说明：" class="headerlink" title="详细说明："></a>详细说明：</h3><p>配置选项：</p>
<ul>
<li>make config ：基于命令行以遍历的方式去配置内核中可配置的每个选项；</li>
<li>make menuconfig ：基于ncurses 方式的配置窗口</li>
<li>make gconfig ：基于gtk开发环境的窗口界面界面；桌面平台开发包组</li>
<li>make xconfig : 基于QT开发环境的窗口界面</li>
</ul>
<p>支持“全新配置”模式进行配置</p>
<ul>
<li>make defconfig ：基于内核为目标平台提供的“默认”为模板进行配置；</li>
<li>make allnoconfig：所有选项为no；基于此选项来定制</li>
</ul>
<h3 id="编译："><a href="#编译：" class="headerlink" title="编译："></a>编译：</h3><ul>
<li>make -j # 多线程编译（提高编译速度）</li>
<li>编译内核中的部分功能<ul>
<li>只编译某子目录中的代码–切换到源码树（cd /usr/src/linux）(make path/to/dir)</li>
<li>只编译一个特定的模块–切换到源码树（编译某个模块的源码,例如xxx.c）(make xxx.ko)（编译完成之后记得要自行复制到相对应的目录中去）(驱动就是/lib/modules/xxxx/driver/)</li>
<li>交叉编译：目标平台与编译操作不同平台<ul>
<li>make ARCH=arch_name</li>
<li>帮助信息：make ARCH=arm help 获取目标平台帮助信息</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="如何在执行编译操作的内核源码树上做重新编译："><a href="#如何在执行编译操作的内核源码树上做重新编译：" class="headerlink" title="如何在执行编译操作的内核源码树上做重新编译："></a>如何在执行编译操作的内核源码树上做重新编译：</h3><ul>
<li>make clean    ：清理编译生成的绝大多数文件，但会保留config文件，以及编译外部模块所需要的文件；</li>
<li>make mrproper ：清理编译生成的所有文件，包括配置生成的config文件以及某些备份文件</li>
<li>make distclean    ：相当于mrproper ，额外清理各种patches以及编辑器备份文件；</li>
</ul>

    </div>

    
    
    
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/06/19/21-Linux%E5%86%85%E6%A0%B8%E6%A8%A1%E5%9D%97%E5%8F%8A%E5%8A%9F%E8%83%BD/" rel="prev" title="Linux内核模块及功能">
      <i class="fa fa-chevron-left"></i> Linux内核模块及功能
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/06/22/23-anaconda%E9%85%8D%E7%BD%AE%E5%AE%9A%E5%88%B6%E8%87%AA%E5%8A%A8%E5%8C%96%E5%AE%89%E8%A3%85Linux/" rel="next" title="23.anaconda配置定制自动化安装Linux">
      23.anaconda配置定制自动化安装Linux <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Linux内核模块功能定制"><span class="nav-number">1.</span> <span class="nav-text">Linux内核模块功能定制</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#编译内核："><span class="nav-number">1.1.</span> <span class="nav-text">编译内核：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#准备工作："><span class="nav-number">1.2.</span> <span class="nav-text">准备工作：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#编译过程"><span class="nav-number">1.3.</span> <span class="nav-text">编译过程</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#screen"><span class="nav-number">1.4.</span> <span class="nav-text">screen:</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#模板文件"><span class="nav-number">1.4.1.</span> <span class="nav-text">模板文件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#（1）配置内核选项"><span class="nav-number">1.5.</span> <span class="nav-text">（1）配置内核选项</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#详细说明："><span class="nav-number">1.5.1.</span> <span class="nav-text">详细说明：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#编译："><span class="nav-number">1.5.2.</span> <span class="nav-text">编译：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#如何在执行编译操作的内核源码树上做重新编译："><span class="nav-number">1.5.3.</span> <span class="nav-text">如何在执行编译操作的内核源码树上做重新编译：</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">lcxiao</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">38</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">分类</span>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">9</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://163.com/" title="http:&#x2F;&#x2F;163.com" rel="noopener" target="_blank">163</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://baidu.com/" title="http:&#x2F;&#x2F;baidu.com" rel="noopener" target="_blank">baidu</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="/dalipan.com" title="dalipan.com">dalipan</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://google.com/" title="https:&#x2F;&#x2F;google.com" rel="noopener" target="_blank">Google</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">lcxiao</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
